//#define __DEBUG__
// by Xeno
#define THIS_FILE "fn_playerhd.sqf"
#include "x_setup.sqf"

#define __shots ["shotBullet","shotShell","shotRocket","shotMissile","shotTimeBomb","shotMine","shotGrenade","shotSpread","shotSubmunitions","shotDeploy","shotBoundingMine","shotDirectionalBomb"]

private ["_unit", "_part", "_dam", "_injurer", "_ammo", "_ddexit"];
PARAMS_5(_unit,_part,_dam,_injurer,_ammo);
__TRACE_1("playerHD","_this");
if (!alive _unit || {_dam == 0}) exitWith {_dam};
if (xr_phd_invulnerable || {GV(_unit,xr_pluncon)}) exitWith {0};
if (GVAR(no_teamkill) == 0 && {_dam >= 0.1} && {!isNull _injurer} && {isPlayer _injurer} && {_injurer != _unit} && {vehicle _unit == _unit} && {side (group _injurer) == side (group _unit)}) exitWith {
	if (_part == "" && {_ammo != ""} && {getText (configFile/"CfgAmmo"/_ammo/"simulation") in __shots} && {time > (__pGetVar(GVAR(tk_cutofft)) + 3)}) then {
		__pSetVar [QGVAR(tk_cutofft), time];
		hint format [(localize "STR_DOM_MISSIONSTRING_497"), name _injurer];
		[QGVAR(unit_tkr), [_unit,_injurer]] call FUNC(NetCallEventCTS);
		if (GVAR(domdatabase)) then {
			[QGVAR(ptkkg), _injurer] call FUNC(NetCallEventCTS);
		};
	};
	0
};
if (_dam >= 0.9 && {time > (_unit getVariable QGVAR(last_gear_save))}) then {
	__TRACE_1("saving respawn gear","_dam");
	_unit setVariable [QGVAR(last_gear_save), time + 2];
	call FUNC(save_respawngear);
};
BIS_hitArray = _this; BIS_wasHit = true;
_dam
